/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.webservicecomponent.metadata.parameter.serializer;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.inspur.edp.caf.cef.schema.base.utils.JsonUtil;
import com.inspur.edp.webservicecomponent.metadata.parameter.HelpFetchValueSetting;

/**
 * @author Kaixuan Shi
 * @version 0.1
 */
public class HelpFetchValueSettingSerializer {

    public static JsonNode serialize(HelpFetchValueSetting helpSetting) {
        JsonNode helpSettingNode = new ObjectMapper().createObjectNode();
        JsonUtil.setPropValue(helpSettingNode, "kind", helpSetting.getKind());
        JsonUtil.setPropValue(helpSettingNode, "helpId", helpSetting.getHelpId());
        JsonUtil.setPropValue(helpSettingNode, "helpCode", helpSetting.getHelpCode());
        JsonUtil.setPropValue(helpSettingNode, "helpName", helpSetting.getHelpName());
        JsonUtil.setPropValue(helpSettingNode, "serviceUnit", helpSetting.getServiceUnit());

        return helpSettingNode;
    }

    public static HelpFetchValueSetting deserialize(JsonNode helpSettingNode) {
        HelpFetchValueSetting helpSetting = new HelpFetchValueSetting();
        helpSetting.setHelpId(JsonUtil.getPropValue(helpSettingNode, "helpId", String.class));
        helpSetting.setHelpCode(JsonUtil.getPropValue(helpSettingNode, "helpCode", String.class));
        helpSetting.setHelpName(JsonUtil.getPropValue(helpSettingNode, "helpName", String.class));
        helpSetting.setServiceUnit(JsonUtil.getPropValue(helpSettingNode, "serviceUnit", String.class));

        return helpSetting;
    }
}
